package com.code.leetcode.before50;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author codeDorado
 * @version 1.0
 * @date 2020/7/11 19:37
 */
public class The17 {
    Map<String, String> phone = new HashMap<String, String>() {{
        put("2", "abc");
        put("3", "def");
        put("4", "ghi");
        put("5", "jkl");
        put("6", "mno");
        put("7", "pqrs");
        put("8", "tuv");
        put("9", "wxyz");
    }};

    List<String> list = new ArrayList<>();

    public void backTrack(String confirm, String next_digits) {
        if(next_digits.length() == 0) {
            list.add(confirm);
        } else {
            String digits = next_digits.substring(0, 1);
            String value = phone.get(digits);
            for (int i = 0; i < value.length(); i++) {
                backTrack(confirm + value.substring(i, i + 1), next_digits.substring(1));
            }
        }
    }

    public List<String> letterCombinations(String digits) {
        if (digits.length() < 1) return list;
        backTrack("", digits);
        return list;
    }
}
